﻿using AFanDa.BLL.BaseService;
using AFanDa.Dto.Base;
using AFanDa.Dto.Reponse;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AFanDa.BLL.BLLService
{
    public class RightService
    {
        BaseRightsService _baseRightsService = null;

        public RightService()
        {
            _baseRightsService = new BaseRightsService();
        }

        /// <summary>
        /// 获取菜单
        /// </summary>
        /// <returns></returns>
        public ApiResult getMenu()
        {
            var iq = _baseRightsService.QueryAll(d => d.RisMenu == 0);

            var data = iq.Select(d => new RightResponseDto()
            {
                id = d.Rid,
                name = d.Rname,
                url = d.Rurl,


            }).ToList();


            data.ForEach(d =>
            {
                d.ChildMenu = getChildMenu(d.id);
            });

            return new ApiResult()
            {
                code = 0,
                message = "获取菜单",
                data = data
            };

        }

        /// <summary>
        /// 获取子菜单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List<RightResponseDto> getChildMenu(string id)
        {
            var iq = _baseRightsService.QueryAll(d => d.RparentId == id);
            List<RightResponseDto> rightResponseDtos = new List<RightResponseDto>();

            rightResponseDtos = iq.Select(d => new RightResponseDto()
            {
                name = d.Rname,
                url = d.Rurl
            }).ToList();


            return rightResponseDtos;


        }
    }
}
